#include #include using namespace std; //function prototypes - promise that you will writh a function with a given signature //purpose - lets you organize your function in logical groupings // lets you not worry about the order of the functions void tradeValues( int& x, int& y); void tradeValues( float& x, float& y); //by copy vs. by reference //by-reference aka by-address //by-copy aka by-value //reference - antoher name for a variable, does not make a copy void square(int& n) { n = n * n; } void main() { //this section is just an example of what a reference is //this is a stupid thing to do, //you never need to names for one variable in one function //float f = 8.9; //float& ref = f; //cout << ref << endl; //cout << f << endl; //ref = 1.1; //cout << ref << endl; //cout << f << endl; int i = 3; int j = 5; //square( i ); float f = 43.23; float g = 1.222; // you can not pass a literal to a function whose parameter is a reference //square( 8 ); tradeValues(i,j); tradeValues(f,g); cout << i << endl; cout << j << endl; cout << f << endl; cout << g << endl; } // function overloading - when you have multiple functions with the same name but different parameters void tradeValues( int& x, int& y) { int temp = x; x = y; y = temp; cout << "Trading integers" << endl; } void tradeValues( float& x, float& y) { int temp = x; x = y; y = temp; cout << "Trading floats" << endl; }